#### "Democracy and Development" ####
# authors: "Pelke, Lars"
# date: 2021-09-03
# written under "R version 34.1.1 (2021-08-10)"

#### Preliminaries ####

R.version$version.string

# clear workspace
rm(list=ls())

# set working directory
setwd("C:/Users/ba72loko/Promotion/Paper/Autocratization and Economic Well-Being/calculations_Nov_2021")


#### Preliminaries ####
library(tidyverse)
library(ggpubr)
library(haven)
library(viridis)
library(hrbrthemes)

#### Load Dataset ####

data_figure_1 <- read_dta("outputs/Step1/data_Figure.dta") 

#### Figure Step 1 ####

ggplot(data = data_figure_1, aes(x = time)) +
  geom_ribbon(aes(ymin=min95, ymax = max95), fill = "#495e35", alpha = 0.5) +
  geom_line(aes(y=min95), color = "#999999", linetype = "dotdash", size = 1.05) +
  geom_line(aes(y=max95), linetype = "dotdash", color = "#999999", size = 1.05) +
  geom_line(aes(y=estimate), size = 1.3, color = "black") +
  geom_hline(aes(yintercept = 0), color = "red", linetype = "dashed", alpha = 0.5) +
  scale_y_continuous(breaks=seq(-5,40,5),  limits=c(-5,30)) +
  scale_x_continuous(breaks=seq(0,35,5)) +
  theme_pubr()+
  labs(x = "Year around democratization", 
       y = "Change in GDP per capita log points") + 
  theme(axis.text=element_text(size=14),
       axis.title=element_text(size=16,face="bold"))

ggsave("outputs/Step1/Figure_3.pdf", units= c("cm"), width = 40, height = 20, dpi = 900)
ggsave("outputs/Step1/Figure_3.eps", units= c("cm"), width = 40, height = 20, dpi = 900)


#### Load Dataset. Additional Robustness test ####

data_figure_1_robust <- read_dta("outputs/Step1/data_Figure_robust.dta") 

#### Figure Step 1 ####

ggplot(data = data_figure_1_robust, aes(x = time)) +
  geom_ribbon(aes(ymin=min95, ymax = max95), fill = "#440154FF", alpha = 0.5) +
  geom_line(aes(y=min95), color = "#999999", linetype = "dotdash", size = 1.05) +
  geom_line(aes(y=max95), linetype = "dotdash", color = "#999999", size = 1.05) +
  geom_line(aes(y=estimate), size = 1.3, color = "black") +
  geom_hline(aes(yintercept = 0), color = "red", linetype = "dashed", alpha = 0.5) +
  scale_y_continuous(breaks=seq(-20,40,5),  limits=c(-20,40)) +
  scale_x_continuous(breaks=seq(0,35,5)) +
  theme_pubr()+
  labs(x = "Year around democratization", 
       y = "Change in GDP per capita log points") +
  theme(axis.text=element_text(size=14),
        axis.title=element_text(size=16,face="bold"))

ggsave("outputs/Step1/Figure_3_robust.pdf", units= c("cm"), width = 40, height = 20, dpi = 900)
ggsave("outputs/Step1/Figure_3_robust.eps", units= c("cm"), width = 40, height = 20, dpi = 900)



